package cn.shyouchi.wuguanjia.android.ui.patrol.report;

import android.view.View;
import android.widget.TextView;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.bingoogolapple.photopicker.activity.BGAPhotoPickerPreviewActivity;
import cn.bingoogolapple.photopicker.widget.BGASortableNinePhotoLayout;
import cn.shyouchi.wuguanjia.android.Global;
import cn.shyouchi.wuguanjia.android.R;
import cn.shyouchi.wuguanjia.android.base.BaseActivity;
import cn.shyouchi.wuguanjia.android.widget.TopBar;

public class PreviewPatrolErrorDetailActivity extends BaseActivity {

    @BindView(R.id.topBar)
    TopBar mTopBar;


    PatrolErrorEntity.ResultMessageBean entity;
    @BindView(R.id.tv_report_order)
    TextView mTvReportOrder;
    @BindView(R.id.tv_report_person)
    TextView mTvReportPerson;
    @BindView(R.id.tv_report_time)
    TextView mTvReportTime;
    @BindView(R.id.tv_report_state)
    TextView mTvReportState;
    @BindView(R.id.tv_report_addr)
    TextView mTvReportAddr;
    @BindView(R.id.tv_report_title)
    TextView mTvReportTitle;
    @BindView(R.id.tv_report_content)
    TextView mTvReportContent;
    @BindView(R.id.photo_snpl)
    BGASortableNinePhotoLayout mPhotoSnpl;

    ArrayList<String> photos = new ArrayList<>();

    @Override
    public int initContentView() {
        return R.layout.activity_preview_patrol_error_detail;
    }

    @Override
    public void initInjector() {
        entity = getIntent().getParcelableExtra("info");
    }

    @Override
    public void initUiAndListener() {
        ButterKnife.bind(this);
        mTopBar.setTitle(getTitle().toString());
        mTopBar.setLeftIcon(R.mipmap.ic_back);
        setSupportActionBar(mTopBar.getToolbar());
        mPhotoSnpl.init(this);
        mPhotoSnpl.setIsSortable(false);
        mPhotoSnpl.setDeleteDrawableResId(R.drawable.photo_del_bg);

        mPhotoSnpl.setDelegate(new BGASortableNinePhotoLayout.Delegate() {
            @Override
            public void onClickAddNinePhotoItem(BGASortableNinePhotoLayout sortableNinePhotoLayout, View view, int position, ArrayList<String> models) {

            }

            @Override
            public void onClickDeleteNinePhotoItem(BGASortableNinePhotoLayout sortableNinePhotoLayout, View view, int position, String model, ArrayList<String> models) {

            }

            @Override
            public void onClickNinePhotoItem(BGASortableNinePhotoLayout sortableNinePhotoLayout, View view, int position, String model, ArrayList<String> models) {
                startActivityForResult(BGAPhotoPickerPreviewActivity.newIntent(mContext, mPhotoSnpl.getMaxItemCount(), models, models, position, false), 2);
            }
        });



        if (entity != null) {
            fillInfo();
        }


    }


    private void fillInfo() {


        mTvReportOrder.setText(entity.getUniqueid());
        mTvReportPerson.setText(entity.getUser().getName());

        mTvReportTime.setText(entity.getTime());
        mTvReportAddr.setText(entity.getInspectionpoint().getInspectionname());
        mTvReportContent.setText(entity.getInspectionpoint().getInspectioncontent());

        mTvReportTitle.setText(entity.getTitle());
        mTvReportContent.setText(entity.getContent());

        for (PatrolErrorEntity.ResultMessageBean.ImageBean imageBean : entity.getImage()) {
            photos.add(Global.BASE_URL + imageBean.getImage());
        }
        mPhotoSnpl.setData(photos);

    }


    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean isApplyStatusBarColor() {
        return true;
    }

//    @Override
//    public boolean onCreateOptionsMenu(Menu menu) {
//        MenuItem menuItem = menu.add("报修");
//        menuItem.setShowAsAction(2);
//        return super.onCreateOptionsMenu(menu);
//    }
//
//    @Override
//    public boolean onOptionsItemSelected(MenuItem item) {
//        if (item.getTitle().equals("报修")) {
//            Intent intent = new Intent(mContext, PatrolRepairActivity.class);
//            intent.putExtra("info", entity);
//            startActivity(intent);
//            finish();
//            return true;
//        }
//        return super.onOptionsItemSelected(item);
//    }


}
